package com.example.rabbitmq.controller.transaction;

import com.example.rabbitmq.Constants;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/producer")
public class AckProducerController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Transactional
    @RequestMapping("/ack")
    public String ack() {
        rabbitTemplate.convertAndSend(Constants.ACK_EXCHANGE,"ack","ack1 test.....");
        try {
            int a = 1 / 0;
        }catch (Exception e) {
            System.out.println("有异常抛出: " + e.toString());
        }
        rabbitTemplate.convertAndSend(Constants.ACK_EXCHANGE,"ack","ack2 test.....");
        return "发送消息成功";
    }
}
